<template>
    <timeLine :list="lineList" :isGt="isTop?2:0" ref="chartEl" :isAddEvent="true" size=""></timeLine>
</template>

<script>

import timeLine from "@/components/chart/timeLine"
export default {
    props:["isTop"],
    components:{
        timeLine,
    },
    data(){
        return{
        }
    },
    inject: ['cfg',"isQry","getSleepTime","isMoneyException","addException"],
    computed:{
        lineList(){
            var list = [];
            if(this.isTop){
                list.push({code:"000001",pre:"1",name:"上证",prePrice:0,rateArr:[],priceArr:[]})
                list.push({code:"399001",pre:"0",name:"深证",prePrice:0,rateArr:[],priceArr:[]})
                list.push({code:"399006",pre:"0",name:"创业板",prePrice:0,rateArr:[],priceArr:[]})
            }else{
                this.cfg.favList.map((item)=>{
                    if(!item.watch) return;
                    list.push({code:item.c,name:item.n,prePrice:0,rateArr:[],priceArr:[]})
                })
            }
            return list || [];
        }
    },
    mounted(){
        this.startTimer();
    },
    methods:{
        startTimer(){
            // this.getLineData();
            this.$once('hook:beforeDestroy', () => {   
                clearTimeout(this.timer);
            })
            this.doTimer();

        },
        doTimer(){
            clearTimeout(this.timer);
            if(this.isQry()){
                this.getLineData();
            }
            var sleep = this.cfg.sleepTime|| this.$config.defSleepTime;
            if(sleep<1000 || isNaN(sleep)) sleep = this.$config.defSleepTime;
            // sleep+=5000; //图形绘制,增加一点延迟
            this.timer = setTimeout(()=>{
                this.doTimer();
            },sleep);
        },
        onRefresh(){
            this.$refs.chartEl.onRefresh()
        },
        getLineData(){
            this.$refs.chartEl.getLineData()
        },
        
    }
}
</script>

<style lang="less" scope>


</style>